<template>
  <div class="middle-container" :style="{backgroundImage: bgImg, color: '#38E5DE'}">
    <div class="title-container">
      <div class="title">
        <img src="../../../assets/img/common/title_tip.png" height="16" width="16" />
        <div class="title-text">{{ title }}</div>
      </div>
      <img src="../../../assets/img/common/close-16px.png" style="cursor: pointer" @click="closeWindow" height="16"
        width="16" />
      <!-- @click="$router.push({ path: '/right-menu/PackageTable'})" -->
    </div>
    <!-- <div class="search-container" v-show="!showDetail">
      <span>日期：</span>
      <el-date-picker v-model="dateRange" type="daterange" range-separator="-" start-placeholder="开始日期"
        end-placeholder="结束日期">
      </el-date-picker>
      <el-button type="primary" class="search-btn" @click="handleSearch">查询</el-button>
    </div> -->
    <!-- <div class="content-container" v-show="!showDetail">
      <div class="echarts-treeChart" ref="treeChart"></div>
    </div> -->
    <div class="detail-container" v-show="showDetail">
      <div class="detail-header-panel">
        <div class="panel-detail">
          <span>冻品名称：</span> <span>帝皇鲜 澳洲和牛M4 + 牛肉卷</span>
        </div>
        <div class="panel-detail">
          <span>原产国：</span> <span>澳大利亚</span>
        </div>
        <div class="panel-detail">
          <span>入境口岸：</span> <span>马湾</span>
        </div>
        <div class="panel-detail">
          <span>生产批号：</span> <span>2021-10-20</span>
        </div>
        <div class="panel-detail">
          <span>保质期时长：</span> <span>12月</span>
        </div>
        <div class="panel-detail fix-panel">
          <span>经营者：</span><span>深圳盒马网络科技有限公司南山区第一分公司</span>
        </div>
        <div class="panel-detail fix-panel">
          <span>溯源哈希：</span><span>9dfk239dsjkksd8923jk</span>
        </div>
      </div>
      <div class="detail-time-panel">
        <div class="time-panel-list">
          <div :class='["time-panel", isActivre== 0 ? "isHeighlight":""]' @click="timePanelEvent(70, 0)">
            <div class="time-content">入境</div>
            <div style="opacity:.5">2021-12-22</div>
          </div>
          <div :class='["time-panel", isActivre== 1 ? "isHeighlight":""]' @click="timePanelEvent(370, 1)">
            <div class="time-content">途中监管</div>
            <div style="opacity:.5">2021-12-22</div>
          </div>
          <div :class='["time-panel", isActivre== 2 ? "isHeighlight":""]' @click="timePanelEvent(670, 2)">
            <div class="time-content">入库</div>
            <div style="opacity:.5">2021-12-22</div>
          </div>
          <div :class='["time-panel", isActivre== 3 ? "isHeighlight":""]' @click="timePanelEvent(940, 3)">
            <div class="time-content">出库</div>
            <div style="opacity:.5">2021-12-22</div>
          </div>
        </div>
        <div class="time-panel-detail">
          <div class="time-panel-triange"></div>
          <ul class="time-panel-info">
            <li :class='["time-panel-li", isActivre== index ? "activeli":""]' v-for="(item,index) in panelList"
              :key="index">
              <div class="time-panel-title">
                <span>01</span>
                <div>
                  <span style="opacity:1">{{item.time}}</span>
                  <span style="opacity:.8">{{item.test}}</span>
                </div>
              </div>
              <div class="time-panel-num">
                <div class="time-Num-box">
                  <span>检验检疫合格证编号</span>
                  <span>12000000025523400001</span>
                </div>
                <div class="time-Num-box">
                  <span>入境日期</span>
                  <span>2021-02-20</span>
                </div>
                <div class="time-Num-box">
                  <span>入境口岸</span>
                  <span>妈湾</span>
                </div>
              </div>
              <div class="time-img">
                <span>检验检疫证明</span>
                <img src="../../../assets/img/common/pos.png" alt="">
              </div>
            </li>
          </ul>
          <img alt="" src="../../../assets/img/common/detail_bg.png">
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { reactive, toRefs, onMounted, ref, defineComponent } from "vue";
import { useRouter } from 'vue-router';
// import echartsUtil from "../../../commons/utils/echartsUtil";
export default defineComponent({
  name: 'ColdChain',
  setup() {
    const treeChart = ref(null)
    const router = useRouter();
    const state = reactive({
      dateRange: [new Date(), new Date()],
      bgImg: 'url(' + require('../../../assets/img/common/middle-bg.png') + ')',
      showDetail: true,
      title: '冷链溯源',
      isActivre: 0,
      treeData: {
        name: "南山冷冻冷藏品",
        normal: {
          backgroundColor: '#725bb8'
        },
        children: [
          {
            name: "南山港入境",
            children: [
              {
                name: "SCT港口", value: 2105,
                children: [

                ]
              },
              { name: "CCT港口", value: 1316 },
              { name: "妈湾港口", value: 3151 },
            ],
          }
        ]
      },
      myChart: null,
      panelList: [
        {
          time: '2121-12-12',
          test: '入境信息'
        }, {
          time: '2121-12-12',
          test: '途中监管'
        }, {
          time: '2121-12-12',
          test: '入库'
        }, {
          time: '2121-12-12',
          test: '出库'
        }
      ]
    })
    const closeWindow = () => {
      // state.title = '冷链溯源'
      // this.router.push({ path: '/right-menu/PackageTable'})
      router.push("/right-menu/PackageTable");
      console.log(router, 'this.$router');
      // this.$router.push({path:'/right-menu/PackageTable'});

    }
    const initMap = () => {
      state.myChart = echartsUtil.initMyChart(treeChart.value)
      const option = {
        tooltip: {
          trigger: 'item',
          triggerOn: 'mousemove'
        },
        legend: {
          top: '2%',
          left: '3%',
          orient: 'vertical',
          data: [
            {
              name: 'tree',
              icon: 'rectangle'
            }
          ],
          borderColor: '#c23531'
        },
        edgeShape: 'polyline',
        expandAndCollapse: true,
        series: [
          {
            type: 'tree',
            name: 'tree1',
            data: [state.treeData],
            top: '5%',
            left: '7%',
            bottom: '2%',
            right: '40%',
            symbolSize: 15,
            tooltip: {
              formatter: function (data) {
                if (data.value) {
                  return data.name + ' ' + data.value + '(吨)'
                } else {
                  return data.name
                }
              }
            },
            label: {
              normal: {
                position: 'center',
                verticalAlign: 'middle',
                align: 'left',
                backgroundColor: '#45A5E5',
                color: '#fff',
                padding: 3,
                // formatter: [
                //     '{box|{b}}'
                // ].join('\n'),
                formatter: function (data) {
                  if (data.data.value) {
                    return '{box|' + data.name + '}' + '(' + '{box|' + data.data.value + '}' + '吨)';
                  } else {
                    return '{box|' + data.name + '}';
                  }

                },
                rich: {
                  box: {
                    height: 40,
                    color: '#fff',
                    padding: [0, 4],
                    align: 'center',
                    borderRadius: 10
                  }
                }
              }
            },
            leaves: {
              label: {
                position: 'right',
                verticalAlign: 'middle',
                align: 'left'
              }
            },
            emphasis: {
              focus: 'descendant'
            },
            expandAndCollapse: true,
            animationDuration: 550,
            animationDurationUpdate: 750
          }
        ]
      }
      state.myChart.setOption(option)
      state.myChart.on("click", treeNodeclick)
    }
    const handleSearch = () => {
      console.log(state.dateRange)
    }
    // 节点点击事件
    const treeNodeclick = (param) => {
      /* true 代表点击的是圆点
      fasle 表示点击的是当前节点的文本
      */
      if (param.event.target.culling === true) {
        return
      } else if (param.event.target.culling === false) {
        let args = param.data; //当前节点及其子节点的值
        const obj = { name: "BA 222323", value: 222 };
        param.data.children.push(obj)
        const option = state.myChart.getOption();
        state.myChart.setOption(option);
        state.showDetail = !state.showDetail
        state.title = '冷链溯源详情'
      }
    }
    const timePanelEvent = (num, active) => {
      console.log(num, active);
      document.querySelector('.time-panel-triange').style.left = `${num}px`
      state.isActivre = active
      console.log(state.isActivre);
    }
    onMounted(() => {
      // initMap()
    })
    return {
      treeChart,
      ...toRefs(state),
      initMap,
      closeWindow,
      handleSearch,
      timePanelEvent
    }
  },

})
</script>
<style>
.middle-container {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  height: 800px;
  width: calc(1200px - 48px);
  padding-left: 24px;
  padding-right: 24px;
}

.title-container {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  height: 46px;
  width: 100%;
  font-size: 18px;
  font-weight: bold;
  /* border-bottom: 1px solid #38E5ED; */
}

.title {
  display: inline-flex;
  align-items: center;
}

.title-text {
  margin-left: 5px;
}
.search-container {
  position: relative;
  color: #fff;
  margin: 20px 0;
  text-align: left;
}
.search-btn {
  margin-left: 15px;
  width: 100px;
}
.content-container {
  height: 600px;
  /* overflow-y: scroll; */
}
.echarts-treeChart {
  width: calc(1200px - 48px);
  height: 600px;
}
.detail-container {
  position: relative;
  padding: 20px 40px 0;
}
.detail-header-panel {
  position: relative;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  overflow: hidden;
  flex-wrap: wrap;
}
.panel-detail {
  position: relative;
  margin-right: 50px;
  margin-bottom: 15px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.65);
}
.panel-detail span:last-child {
  font-size: 14px;
  color: #ffffff;
}
.fix-panel {
  flex: 0 0 100%;
  text-align: left;
}
.detail-body-panel {
  position: inherit;
  margin-top: 60px;
}
.time-panel-list {
  position: relative;
  border-bottom: 3px solid #406e8e;
  display: flex;
  justify-content: space-between;
  padding: 26px 72px;
}
/* .time-panel-list::before {
  content: url(../../../assets/img/common/left_arrow.png);
  width: 23px;
  height: 40px;
  position: absolute;
  bottom: -21px;
  left: -1px;
} */
.time-panel-list::after {
  width: 25px;
  height: 25px;
  border-left: 3px solid #01d3fd;
  border-top: 3px solid #01d3fd;
  transform: rotate(135deg);
  content: "";
  position: absolute;
  right: 0px;
  top: 82px;
}
.time-panel {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  position: relative;
}
.time-panel::after {
  content: url(../../../assets/img/common/round.png);
  width: 26px;
  height: 26%;
  position: absolute;
  opacity: .5;
  bottom: -30px;
  left: 50%;
  transform: translate(-50%, -50%);
}
.isHeighlight {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  position: relative;
}
/* 设置动画前颜色 */
/* .isHeighlight:after {
    background-color: #2ea598;
  } */

/* 设置动画后颜色 */
.isHeighlight:before {
  content: url(../../../assets/img/common/round.png);
}
.isHeighlight::after {
  content: url(../../../assets/img/common/round_green.png);
  /* width: 26px;
  height: 26%;
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translate(-50%, -50%);
  cursor: pointer; */
}
.isHeighlight:before,
.isHeighlight:after {
  content: url(../../../assets/img/common/round_green.png);
  width: 26px;
  height: 26%;
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translate(-50%, -50%);
  cursor: pointer;
  animation: warn 2s ease-out 0s infinite;
}

@keyframes warn {
  0% {
    /* transform: scale(0.5); */
    opacity: 1;
  }

  30% {
    opacity: 1;
  }

  100% {
    /* transform: scale(1.4); */
    opacity: 0;
  }
}
.time-content {
  color: #07c0e4;
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 5px;
}
.time-panel-detail {
  position: relative;
  width: 950px;
  height: 394px;
  background: #45a5e5;
  border-radius: 5px;
  margin-top: 40px;
  margin-left: 30px;
  padding: 35px 30px;
  /* overflow: auto; */
}
.time-panel-info {
  width: 950px;
  height: 394px;
  padding-left: 0;
  overflow: hidden;
}
.time-panel-li {
  list-style: none;
  display: none;
}
.activeli {
  display: block;
}
.time-panel-title {
  position: relative;
  display: flex;
  justify-content: flex-start;
  margin-bottom: 25px;
}
.time-panel-title > span {
  font-size: 60px;
  font-weight: normal;
  color: #ffffff;
  opacity: 0.5;
  padding-right: 5px;
}
.time-panel-title > div {
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  text-align: left;
  opacity: 0.8;
}
.time-panel-title > div > span {
  display: block;
  font-size: 22px;
  font-weight: 600;
  color: #ffffff;
}
.time-panel-num {
  display: flex;
  justify-content: space-between;
}
.time-Num-box {
  font-size: 14px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.65);
}
.time-Num-box span {
  display: block;
  text-align: left;
  margin-bottom: 5px;
}
.time-img {
  position: relative;
  width: 100%;
  margin-top: 25px;
  text-align: left;
}
.time-img > span {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.65);
  margin-bottom: 5px;
  text-align: left;
}
.time-img > img {
  width: 175px;
  height: 216px;
}
.time-panel-detail > img {
  position: absolute;
  bottom: 0;
  right: 0;
}
.time-panel-triange {
  width: 0;
  height: 0;
  border-left: 16px solid transparent;
  border-right: 16px solid transparent;
  border-bottom: 16px solid #45a5e5;
  font-size: 0;
  line-height: 0;
  position: absolute;
  left: 82px;
  top: -8px;
  transform: translateY(-50%);
}
</style>